﻿@using X.PagedList.Mvc.Core
@using X.PagedList.Web.Common
@using Personalblog.Model.ViewModels
@using Personalblog.Utils
@model PhotographyViewModel


@{
    ViewBag.Title = "摄影";
}
<div class="container px-4 py-3">
    <h2 class="d-flex w-100 justify-content-between pb-2 mb-3 border-bottom">
        <div>Photography</div>
        <div>@Model.photos.TotalItemCount.ToString() Photos</div>
    </h2>
    <p class="status">&nbsp;</p>
    @if(Model.photos.Any()){
        <div class="row row-photo" data-masonry='{"percentPosition": true }'>
            @foreach (var photo in Model.photos)
            {
                <div class="col-sm-6 col-lg-4 mb-4">
                    @await Html.PartialAsync("Widgets/PhotoCard",model:photo)
                    @*                    <partial name="Widgets/PhotoCard" model="photo" />*@
                </div>
            }
        </div>

        <nav aria-label="Page navigation example" class="mt-3">
            @Html.PagedListPager(Model.photos, page => Url.Action(
                RazorHelper.GetCurrentActionName(ViewContext), new {page}),
                new PagedListRenderOptions {
                    LiElementClasses = new[] {"page-item"},
                    PageClasses = new[] {"page-link"},
                    UlElementClasses = new[] {"pagination justify-content-center"}
                })
        </nav>
    }else {
        <div class="d-flex justify-content-center">
            <div class="card" style="width: 18rem;">
                <img src="~/images/codelab.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">当前没有图片数据</h5>
                    <p class="card-text">No photos.</p>
                    <a class="btn btn-primary" asp-controller="Home" asp-action="Index">返回主页</a>
                </div>
            </div>
        </div>
    }
</div>
@section bottom
{
    <script src="~/js/imagesloaded.pkgd.js"></script>
    <script src="~/js/masonry.pkgd.min.js"></script>
    @* <script type="text/javascript">document.write("<scr"+"ipt src=\"js/imagesloaded.pkgd.js\"></sc"+"ript>") *@
    @* </script> *@
    <script>
    $.noConflict();
    jQuery(document).ready(function ($){
          var $status = $(".status");
          $(".img-grid").imagesLoaded({
              background: true
          }, function (imgLoad) {
              $status.text(imgLoad.images.length + ' Picture loading completed');
          }
          );
          var $grid = $('.row-photo').masonry({
              //itemSelector: '.img-grid',
              percentPosition: true,
              //columnWidth: '.img-grid'
          });
          // layout Masonry after each image loads
          $grid.imagesLoaded().progress(function () {
              $grid.masonry();
          });
    });
    </script>
}
